package com.iee.concurrent.thread;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/**
 *@ClassName SchuduleExecutorDemo2
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2022/5/5 0005 18:40
 */
@Slf4j
public class SchuduleExecutorDemo2 {
    static ThreadFactory guavaThreadFactory = new ThreadFactoryBuilder().setNameFormat("retryClient-pool-%d").build();
    static ScheduledExecutorService pruneTimer1 = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2 + 1, guavaThreadFactory);

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            String ii = String.valueOf(i);
            pruneTimer1.scheduleWithFixedDelay(() -> {
                log.info("xxxxx"+ii);
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }, 1, 1, TimeUnit.SECONDS);
        }
    }
}
